package ioperations;

import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOPeration{
    public void work(BookList bookList){
        System.out.println("删除图书...");
        System.out.println("输入你想删除图书：");
        Scanner scanner=new Scanner(System.in);
        String name= scanner.nextLine();
        int pos=-1;
        int currentSize= bookList.getUsedSize();
        int i = 0;
        for (; i <currentSize; i++) {
            if(name.equals(bookList.getBooks(i).getName())){
                pos=i;
                break;
            }
        }
        if(i==currentSize) {
            System.out.println("没找到你想要删除的图书");
        }
        for (int j = pos; j <currentSize-1; j++) {
            bookList.setBooks(pos,bookList.getBooks(j+1));
        }
        bookList.setUsedSize(currentSize-1);
        System.out.println("删除成功");
        }
}
